﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TPOJ.ICacheDependency;
using System.Configuration;
using System.Reflection;

namespace TPOJ.CacheDependencyFactory
{
    public static class DependencyAccess
    {
        public static ITPOJCacheDependency CreateProblemDependency()
        {
            return LoadInstance("Problem");
        }

        public static ITPOJCacheDependency CreateSolutionDependency()
        {
            return LoadInstance("Solution");
        }

        public static ITPOJCacheDependency CreateContestDependency()
        {
            return LoadInstance("Contest");
        }

        public static ITPOJCacheDependency CreateStandingDependency()
        {
            return LoadInstance("Standing");
        }

        public static ITPOJCacheDependency CreateAccountDependency()
        {
            return LoadInstance("Account");
        }

        public static ITPOJCacheDependency CreateForumMessageDependency()
        {
            return LoadInstance("ForumMessage");
        }

        private static ITPOJCacheDependency LoadInstance(string className)
        {
            string path = ConfigurationManager.AppSettings["CacheDependencyAssembly"];
            string fullQulifiedClass = path + className;

            return (ITPOJCacheDependency)Assembly.Load(path).CreateInstance(fullQulifiedClass);
        }        
    }
}
